package element;


import java.awt.*;

import static utils.Constant.*;

/**
 * @author 邓哈哈
 * 2023/2/19 20:45
 * Function:
 * Version 1.0
 */

public class BackGround {
    //背景图片
    Image bg = Toolkit.getDefaultToolkit().getImage("src/main/imgs/bg.jpg");
    Image bg1 = Toolkit.getDefaultToolkit().getImage("src/main/imgs/bg1.jpg");
    Image person = Toolkit.getDefaultToolkit().getImage("src/main/imgs/peo.png");
    Image water = Toolkit.getDefaultToolkit().getImage("src/main/imgs/water.png");
    Image goldMiner = Toolkit.getDefaultToolkit().getImage("src/main/imgs/GoldMiner.png");
    Image goldMiner2 = Toolkit.getDefaultToolkit().getImage("src/main/imgs/GoldMiner2.jpg");

    /**
     * 初始化工作
     */
    public BackGround() {
    }

    /**
     * 游戏准备中
     *
     * @param g
     */
    public void paintPrepare(Graphics g) {
        //绘制地面
        g.drawImage(this.bg, 0, 200, null);
        //绘制天空
        g.drawImage(this.bg1, 0, 0, null);
        //绘制原游戏图
        g.drawImage(this.goldMiner, 55, 700, null);
        g.drawImage(this.goldMiner2, 385, 696, null);

        //绘制文字
        drawWords(g, "操作提示", 24, Color.RED, 20, 60);
        drawWords(g, "游戏中按下\"鼠标左键\"可实现抓取", 20, Color.RED, 20, 90);
        drawWords(g, "游戏中按下\"鼠标右键\"可使用药水", 20, Color.RED, 20, 120);
        drawWords(g, "在限定时间内,达到对应积分要求即可过关", 20, Color.RED, 20, 150);
        drawWords(g, "游戏规则就是如此简单,祝您游戏愉快!", 20, Color.RED, 20, 180);

        drawWords(g, "奉上本作原游戏图", 35, Color.GREEN, 240, 680);

        drawWords(g, "欢迎试玩", 50, Color.GREEN, 295, 300);
        drawWords(g, "黄金矿工怀旧版", 70, Color.YELLOW, 150, 400);
        drawWords(g, "按下\"鼠标左键\"开始游戏", 30, Color.BLACK, 230, 450);
    }

    /**
     * 游戏进行中
     */
    public void paintSelf(Graphics g) {
        //绘制地面
        g.drawImage(this.bg, 0, 200, null);
        //绘制天空
        g.drawImage(this.bg1, 0, 0, null);
        //绘制矿工
        g.drawImage(this.person, 310, 50, null);
        //绘制药水
        g.drawImage(this.water, 450, 40, null);
        //绘制文字信息
        drawWord(g);
    }

    /**
     * 绘制文字信息
     * 绘制积分榜 , 绘制关卡数 , 绘制药水数量
     *
     * @param g
     */
    public void drawWord(Graphics g) {
        //绘制积分榜
        drawWords(g, "积分:" + COUNT, 30, Color.GREEN, 20, 105);
        drawWords(g, "目标:" + GOAL_COUNT, 30, Color.GREEN, 20, 140);
        //绘制关卡数
        drawWords(g, "第" + LEVEL + "关", 30, Color.GREEN, 20, 70);
        //绘制药水数量
        drawWords(g, "*" + WATER_COUNT, 30, Color.BLACK, 510, 70);
        //绘制倒计时
        drawTime(g);
    }

    /**
     * 绘制倒计时
     *
     * @param g
     */
    public void drawTime(Graphics g) {
        g.setColor(Color.GREEN);
        END_TIME = System.currentTimeMillis();
        TIM = 60 - (END_TIME - START_TIME) / 1000;

        if (TIM < 11) {
            drawWords(g, "时间:" + (TIM > 0 ? TIM : 0) + "s", 30, Color.RED, 620, 80);
            return;
        }

        drawWords(g, "时间:" + TIM + "s", 30, Color.GREEN, 620, 80);
    }

    /**
     * 游戏成功
     *
     * @param g
     */
    public void paintWin(Graphics g) {
        //绘制地面
        g.drawImage(this.bg, 0, 200, null);
        //绘制天空
        g.drawImage(this.bg1, 0, 0, null);
        //绘制文字
        drawWords(g, "成功", 100, Color.GREEN, 200, 400);
//        drawWords(g, "按下 \"鼠标左键\" 进行下一局游戏", 30, Color.BLACK, 200, 500);
//        drawWords(g, "按下 \"鼠标右键\" 进行退出至菜单", 30, Color.BLACK, 200, 600);
        drawWords(g, "3秒后自动进入下一关卡", 30, Color.BLACK, 200, 600);
    }

    /**
     * 游戏失败
     *
     * @param g
     */
    public void paintFail(Graphics g) {
        //绘制地面
        g.drawImage(this.bg, 0, 200, null);
        //绘制天空
        g.drawImage(this.bg1, 0, 0, null);
        //绘制文字
        drawWords(g, "游戏失败", 100, Color.RED, 200, 400);
        drawWords(g, "3秒后自动进入下一关卡", 30, Color.BLACK, 200, 600);
    }
}


